package xian.woniuxy.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import xian.woniuxy.dao.TypeMapper;
import xian.woniuxy.entity.Type;
import xian.woniuxy.service.ITypeService;
import xian.woniuxy.utils.Pageable;
import xian.woniuxy.util.MybatisUtils;
import java.util.List;

@Service
@Transactional
public class TypeServiceImpl implements ITypeService {

    @Autowired
    private TypeMapper typeMapper;

    @Override
    public Pageable findAll(int page, int size) {
        List<Type> all = typeMapper.findAll(page, size);

        int count = typeMapper.Count();

        int pageCount = count / size + (count % size != 0 ? 1 : 0);

        Pageable pageable = new Pageable(pageCount, count,  all, size, page);


        return pageable;
    }

    @Override
    public List<Type> findAll() {
        return null;
    }

    @Override
    public List<Type> findByTypeName(String type_name) {
        List<Type> allType = typeMapper.findByTypeName(type_name);

        return allType;
    }
    @Override
    public void save(Type type) {
        typeMapper.save(type);
        }

    @Override
    public void deleteById(int id) {
        typeMapper.deleteById(id);
    }

    @Override
    public void upd(Type type) {
        typeMapper.upd(type);
    }
}